// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var transportNoticeId;
	var noticeState;
	var constant = require("constant");
	var financeId;
    var left;
	var css_detail = require("./transportNoticeDetail.css");
	var init = function(page) {
		transportNoticeId = page.params.transportNoticeId;
		inquireTransportNoticeDetail();
		noticeState = page.params.noticeState||base.getUrlParam("noticeState");
    	left = base.getUrlParam("left");
		
		initEvent();
		router.init();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
	};

	// 查询收货通知列表
	var inquireTransportNoticeDetail = function() {

		base.fnAjax({
			action: "inquireTransportNoticeDetail.json",
			oData: {
				recieveNoticeId: transportNoticeId
			}, // 传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					financeId = data.datas[0].financeId;
					databind.fillInput($("#transportNoticeDetail"), {
						action: "inquireTransportNoticeDetail.json?recieveNoticeId=" + transportNoticeId
					});
					var tpl = $("#noticeDetailTpl").html();
					var html = juicer(tpl, data);
					$("#noticeDetailBody").html(html);
					var noticeState = $("#noticeState").val();
					if (noticeState == 1) {
						$("#confirmTrans").removeClass("none");
					} else if (noticeState == 2) {
						$("#cancelTrans").removeClass("none");
					}
					inquireFinanceApplicationDetail();
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	
	// 融资详情
	var inquireFinanceApplicationDetail = function() {

		base.fnAjax({
			action: "inquireFinanceApplicationDetail.json",
			oData: {
				financeId: financeId
			}, // 传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#bookingSpaceTpl").html();
					var html = juicer(tpl, data);
					$("#bookingSpaceBody").append(html);
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}

	return {
		init: init
	};
});